package com.ruoyi.supply.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.supply.enums.DfStatusEnum;
import com.ruoyi.supply.enums.MemberConsumeTypeEnum;
import com.ruoyi.supply.enums.PayStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * @author huangxiong
 * @date 2025/06/14 15:55
 */
@Data
@NoArgsConstructor
@TableName("t_member_consume_log")
public class TMemberConsumeLog {
    @TableId(type = IdType.ASSIGN_ID)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty("id")
    private Long id;

    private Long fkMemberId;

    private String fkTableId;

    private String fkTableType;

    private String remark;

    private BigDecimal price;

    private String status;

    private String orderNo;

    @ApiModelProperty("额外信息")
    private String extra;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;


    public static TMemberConsumeLog build(MemberConsumeTypeEnum typeEnum,Long fkTableId, BigDecimal price,Long userId,String orderNo,String extra){
        TMemberConsumeLog tMemberConsumeLog = new TMemberConsumeLog();
        tMemberConsumeLog.setFkMemberId(userId);
        tMemberConsumeLog.setFkTableId(Objects.isNull(fkTableId)?null:fkTableId.toString());
        tMemberConsumeLog.setFkTableType(typeEnum.getCode());
        tMemberConsumeLog.setCreateTime(new Date());
        tMemberConsumeLog.setPrice(price);
        tMemberConsumeLog.setStatus(PayStatusEnum.ING.getCode());
        tMemberConsumeLog.setOrderNo(orderNo);
        tMemberConsumeLog.setExtra(extra);
        return tMemberConsumeLog;
    }
    public static TMemberConsumeLog build(MemberConsumeTypeEnum typeEnum,Long fkTableId, BigDecimal price,Long userId,String orderNo){
        return build(typeEnum, fkTableId, price, userId,orderNo,null);
    }
    public static TMemberConsumeLog buildFail(MemberConsumeTypeEnum typeEnum,Long fkTableId, BigDecimal price,Long userId,String orderNo,String remark){
        TMemberConsumeLog tMemberConsumeLog = build(typeEnum, fkTableId, price, userId,orderNo);
        tMemberConsumeLog.setRemark(remark);
        tMemberConsumeLog.setStatus(PayStatusEnum.FAIL.getCode());
        return tMemberConsumeLog;
    }

}
